const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    createStaffBalance: 0,//名额
    usedStaffBalance: 0,//已使用名额
    userInfo:{},
    isred:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ userInfo: app.globalData.userInfo})
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDistributor();
    this.getMyPayRequests();
  },

  //获取免费名额
  getDistributor:function(){
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Distributor/GetDistributor?userId=' + app.globalData.userInfo.Uid,
      success: function(res) {
        if(res.data.Code == 0){
          that.setData({
            createStaffBalance: res.data.Data.CreateStaffBalance,//名额
            usedStaffBalance: res.data.Data.UsedStaffBalance//已使用名额
          })
        }
      }
    })
  },

  //申请免费额度扩容
  requestStaffBalance:function(){
    wx.request({
      url: app.globalData.host + '/api/Distributor/RequestStaffBalance?uid=' + app.globalData.userInfo.Uid,
      success: function(res) {
        if(res.data.Code == 0){
          wx.showToast({
            title: '申请成功'
          })
        }else{
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },
  //获取待确认列表
  getMyPayRequests: function () {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Staff/GetMyPayRequests?uid=' + app.globalData.userInfo.Uid + '&status=0' + '&page=1',
      success: function (res) {
        if (res.data.Code == 0) {
          let list = res.data.Data;
          if (list.length > 0) {
            that.setData({
              isred: true
            })
          }else{
            that.setData({
              isred: false
            })
          }
        }
      }
    })
  },
  
})